package com.example.viewpagertest2;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TableRow;

/**
 * Created by Michael on 2015/3/31.
 */
public class RuleView extends RelativeLayout {

    private Button timeButton;

    private Button heatButton;

    private Button ruleButton;

    private Button hideButton;

    private TableRow ruleTableRow;

    private RuleInterface ruleInterface;

    private LinearLayout ruleLinearLayout;

    public RuleView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);

        View view = LayoutInflater.from(context).inflate(R.layout.rule_layout, this);
        ruleTableRow = (TableRow) view.findViewById(R.id.rule_table_row);
        timeButton = (Button) view.findViewById(R.id.time_button);
        heatButton = (Button) view.findViewById(R.id.heat_button);
        ruleButton = (Button) view.findViewById(R.id.rule_button);
//        hideButton = (Button) view.findViewById(R.id.hide_button);
        ruleLinearLayout = (LinearLayout) view.findViewById(R.id.rule_linear_layout);

        timeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ruleInterface.timeButtonListener();
                ruleLinearLayout.setVisibility(GONE);
            }
        });

        heatButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ruleInterface.heatButtonListener();
                ruleLinearLayout.setVisibility(GONE);
            }
        });
//
//        hideButton.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ruleLinearLayout.setVisibility(GONE);
//            }
//        });
        ruleButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                ruleTableRow.setVisibility(VISIBLE);
                ruleLinearLayout.setVisibility(VISIBLE);
            }
        });
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ruleLinearLayout.setVisibility(GONE);
            }
        });
    }

    public void setRuleInterface(RuleInterface rule) {
        ruleInterface = rule;
    }

    public void hideView(){
        ruleLinearLayout.setVisibility(GONE);
    }

}